<template>
  <div>
    <Bread></Bread>
    <el-card class="box-card">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-input placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <el-col :span="6" >
          <el-button type="primary" @click="getAdd">添加商品</el-button>
        </el-col>
      </el-row>

      <template>
        <el-table :data="data.goods" border style="width: 100%">
          <el-table-column type="index" prop="#"></el-table-column>
          <el-table-column prop="goods_name" label="商品名称" width="500"></el-table-column>
          <el-table-column prop="goods_price" label="商品价格(元)"></el-table-column>
          <el-table-column prop="goods_weight" label="商品重量"></el-table-column>
          <el-table-column prop="upd_time" label="创建时间"></el-table-column>
          <el-table-column label="操作"></el-table-column>
        </el-table>
      </template>
      <el-pagination
       background 
       layout="prev, pager, next" 
       :page-size='goodslist.pagesize'
       :current-change='goodslist.pagenum'
       :total="data.total"
    @current-change="getnowpage"
       ></el-pagination>
    </el-card>
  </div>
</template>

<script>
import Bread from "@/components/breadmenu";
export default {
  components: { Bread },
  data() {
    return {
      goodslist: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      data:{}
    };
  },
  methods: {
    async getgoods() {
      var { data } = await this.$http.get(
        "/goods?query=" +
          this.goodslist.query +
          "&pagenum=" +
          this.goodslist.pagenum +
          "&pagesize=" +
          this.goodslist.pagesize
      );
      console.log(data);
      this.data = data.data;
      console.log(this.data);
    },

    getnowpage(nowpage){
        this.goodslist.pagenum=nowpage
        this.getgoods()
    },
    //添加商品
      getAdd(){
      this.$router.push("/getadd")
       var obj = {'one':"商品管理",'two':"添加商品"};
      // console.log(one,two)
      sessionStorage.setItem("path",JSON.stringify(obj))
  },
  },


  mounted() {
    this.getgoods();
  }
};
</script>
<style lang="scss" scoped>
.el-card {
  margin-top: 20px;
}
</style>